
	int toolsSelIndex = 0;
	int cardSelIndex = 0;
	final static int TOOLS_STATE_MAIN = 0;
	final static int TOOLS_STATE_CARDS = TOOLS_STATE_MAIN + 1;
	final static int TOOLS_STATE_OBJECTIVE = TOOLS_STATE_CARDS + 1;
	int toolsState = TOOLS_STATE_MAIN;
	
	int[] shownCards;
	
	int firstCardShown = 0;
	int selCardIndex = 0;

	public void UpdateIngameTools()
	{
		switch(toolsState)
		{
			case TOOLS_STATE_MAIN:
			
				drawMap();
				#ifdef USE_DRAWRGB
				cGame_g.setColor(MENUS.MAIN_MENU_BACKGROUND_COLOR);
				cGame_g.drawAlphaRect(INGAME.VIEWPORT_X, INGAME.VIEWPORT_Y, INGAME.VIEWPORT_W, INGAME.VIEWPORT_H, MENUS.MAIN_MENU_ALPHA_LEVEL);
				#endif
			
				int entryHeight = cGame_g.getFontHeight() + cGame_g.getFontPixelSize() * 2;
				
				int maxWidth = 0;
				for(int j = 0; j < TEXT.INGAME_TOOLS_ENTRIES.length; j++)
				{
					if(cGame_g.getStringWidth(TEXT.INGAME_TOOLS_ENTRIES[j]) > maxWidth)
						maxWidth = cGame_g.getStringWidth(TEXT.INGAME_TOOLS_ENTRIES[j]);
				}
				maxWidth += cGame_g.getFontPixelSize() * 2;
			
				for(int i = 0; i < TEXT.INGAME_TOOLS_ENTRIES.length; i++)
				{
					cGame_g.setColor(MENUS.MAIN_MENU_BACKGROUND_COLOR);
					cGame_g.fillRect(0, SCREEN_HEIGHT - INGAME.VIEWPORT_Y - TEXT.INGAME_TOOLS_ENTRIES.length * entryHeight + i * entryHeight, maxWidth, entryHeight);
					cGame_g.setColor(MENUS.MAIN_MENU_FOREGROUND_COLOR);
					cGame_g.drawRect(0, SCREEN_HEIGHT - INGAME.VIEWPORT_Y - TEXT.INGAME_TOOLS_ENTRIES.length * entryHeight + i * entryHeight, maxWidth, entryHeight);
					if(toolsSelIndex==i)
						cGame_g.setFontColor(MENUS.MAIN_MENU_HIGHLIGHT_COLOR);
					else
						cGame_g.setFontColor(MENUS.MAIN_MENU_FOREGROUND_COLOR);
					cGame_g.drawString(TEXT.INGAME_TOOLS_ENTRIES[i], cGame_g.getFontPixelSize(), SCREEN_HEIGHT - INGAME.VIEWPORT_Y - TEXT.INGAME_TOOLS_ENTRIES.length * entryHeight + i * entryHeight + cGame_g.getFontPixelSize(), DSmallFont.LEFT | DSmallFont.TOP);
				}
				
				drawSoftKeys(SOFTKEYS.STR_CLOSE, SOFTKEYS.STR_NONE);
				
				if(isKeyPressed(KEYS.KEY_UP) && toolsSelIndex > 0)
				{
					toolsSelIndex--;
					clearKeys();
				}
				else if(isKeyPressed(KEYS.KEY_DOWN) && toolsSelIndex < TEXT.INGAME_TOOLS_ENTRIES.length - 1)
				{
					toolsSelIndex++;
					clearKeys();
				}
				else if(isKeyPressed(KEYS.KEY_FIRE) || isKeyPressed(KEYS.KEY_5))
				{
					toolsState = toolsSelIndex + 1;
					clearKeys();
				}
				else if(isKeyPressed(KEYS.KEY_LSK))
				{
					toolsSelIndex = 0;
					SetIngameState(prev_ingame_state);
					clearKeys();
				}
				
			break;
			
			case TOOLS_STATE_CARDS:
			
				cGame_g.setFont(DGraph.FONT_SMALL);
			
				if(shownCards == null)
				{
					shownCards = new int[3];
					
					for(int n = 0; n < shownCards.length; n++)
					{
						shownCards[n] = -1;
					}
				}
			
				int toolsCountries = 0;
				int cardListIndex = 0;
				int maxCardsShown = CARDS.CARD_HEIGHT / (cGame_g.getFontHeight() + cGame_g.getFontPixelSize());
								
				for(int i = 0; i < COUNTRY_INFO.TOTAL_COUNTRIES; i++)
				{
					if(tegCountries[i].cardOwner == cPlayer.turn)
						toolsCountries++;
				}
				
				int[] cardList = new int[toolsCountries];
				
				if(toolsCountries > 0)
				{
					for(int l = 0; l < COUNTRY_INFO.TOTAL_COUNTRIES; l++)
					{
						if(tegCountries[l].cardOwner == cPlayer.turn)
						{
							cardList[cardListIndex] = l;
							cardListIndex++;
						}
					}
				}
				
				cGame_g.setFont(DGraph.FONT_BIG);
				if(shownCards[0] != -1 && tegCountries[shownCards[0]].owner == cPlayer.turn && shownCards[1] == -1 && shownCards[2] == -1 && !tegCountries[shownCards[0]].usedCard)
				{
					cGame_g.setFontColor(SOFTKEYS.COLOR);
					drawSoftKeys(SOFTKEYS.STR_GET_ARMIES, SOFTKEYS.STR_BACK);
				}
				else if(shownCards[0] != -1 && shownCards[1] != -1 && shownCards[2] != -1)
				{
					if(((tegCountries[shownCards[0]].cardImage == tegCountries[shownCards[1]].cardImage) && (tegCountries[shownCards[0]].cardImage == tegCountries[shownCards[2]].cardImage)) || ((tegCountries[shownCards[0]].cardImage != tegCountries[shownCards[1]].cardImage) && (tegCountries[shownCards[0]].cardImage != tegCountries[shownCards[2]].cardImage) && (tegCountries[shownCards[1]].cardImage != tegCountries[shownCards[2]].cardImage)))
					{
						cGame_g.setFontColor(SOFTKEYS.COLOR);
						drawSoftKeys(SOFTKEYS.STR_CHANGE_CARDS, SOFTKEYS.STR_BACK);
					}
				}
				else
				{
					cGame_g.setFontColor(SOFTKEYS.COLOR);
					drawSoftKeys(SOFTKEYS.STR_NONE, SOFTKEYS.STR_BACK);
				}
					
				cGame_g.setFont(DGraph.FONT_SMALL);
				cGame_g.setColor(MENUS.MAIN_MENU_BACKGROUND_COLOR);
				cGame_g.fillRect(0, INGAME.VIEWPORT_Y, SCREEN_WIDTH - 1, SCREEN_HEIGHT - INGAME.VIEWPORT_Y * 2 + 2);
				cGame_g.setColor(MENUS.MAIN_MENU_FOREGROUND_COLOR);
				cGame_g.drawRect(0, INGAME.VIEWPORT_Y, SCREEN_WIDTH - 1, SCREEN_HEIGHT - INGAME.VIEWPORT_Y * 2 + 2);
				
				for(int k = 0; k < 2; k++)
				{
					if(!(k == 1 && shownCards[2] != -1))
					{
						cGame_g.setColor(MENUS.MAIN_MENU_FOREGROUND_COLOR);
						cGame_g.drawRect(0 + CARDS.INGAME_TOOLS_CARD_SPACING, INGAME.VIEWPORT_Y + CARDS.INGAME_TOOLS_CARD_SPACING * (k + 1) + CARDS.CARD_HEIGHT * k, CARDS.CARD_WIDTH, CARDS.CARD_HEIGHT);
					}
					else
					{
						drawCard(0 + CARDS.INGAME_TOOLS_CARD_SPACING, INGAME.VIEWPORT_Y + CARDS.INGAME_TOOLS_CARD_SPACING * (k + 1) + CARDS.CARD_HEIGHT * k, shownCards[2]);
						cGame_g.setFont(DGraph.FONT_SMALL);
					}
				}
				
				for(int j = 0; j < 2; j++)
				{
					if(shownCards[j] == -1)
					{
						cGame_g.setColor(MENUS.MAIN_MENU_FOREGROUND_COLOR);
						cGame_g.drawRect(SCREEN_WIDTH - CARDS.CARD_WIDTH - CARDS.INGAME_TOOLS_CARD_SPACING, INGAME.VIEWPORT_Y + CARDS.INGAME_TOOLS_CARD_SPACING * (j + 1) + CARDS.CARD_HEIGHT * j, CARDS.CARD_WIDTH, CARDS.CARD_HEIGHT);
					}
					else
					{
						drawCard(SCREEN_WIDTH - CARDS.CARD_WIDTH - CARDS.INGAME_TOOLS_CARD_SPACING, INGAME.VIEWPORT_Y + CARDS.INGAME_TOOLS_CARD_SPACING * (j + 1) + CARDS.CARD_HEIGHT * j, shownCards[j]);
						cGame_g.setFont(DGraph.FONT_SMALL);
					}
				}
				
				if(selCardIndex > cardList.length)
					selCardIndex = 0;
				
				if(toolsCountries > 0)
				{
					for(int m = firstCardShown; m < ((maxCardsShown > cardList.length)? cardList.length : maxCardsShown); m++)
					{
						if(selCardIndex == m)
							cGame_g.setFontColor(MENUS.MAIN_MENU_HIGHLIGHT_COLOR);
						else
							cGame_g.setFontColor(MENUS.MAIN_MENU_FOREGROUND_COLOR);
						
						cGame_g.drawString(tegCountries[cardList[m]].name, CARDS.INGAME_TOOLS_CARD_SPACING + cGame_g.getFontPixelSize() * 2, INGAME.VIEWPORT_Y + CARDS.INGAME_TOOLS_CARD_SPACING + cGame_g.getFontPixelSize() * 2 + cGame_g.getFontPixelSize() * m + cGame_g.getFontHeight() * m, DSmallFont.TOP | DSmallFont.LEFT);
					}
				}
				
				if(isKeyPressed(KEYS.KEY_UP) && selCardIndex > 0)
				{
					selCardIndex--;
					clearKeys();
				}
				else if(isKeyPressed(KEYS.KEY_DOWN) && selCardIndex < cardList.length - 1)
				{
					selCardIndex++;
					clearKeys();
				}
				else if((isKeyPressed(KEYS.KEY_FIRE) || isKeyPressed(KEYS.KEY_5)) && cardList.length > 0)
				{
					boolean alreadyShown = false;
					
					for(int r = 0; r < shownCards.length; r++)
					{
						if(shownCards[r] == cardList[selCardIndex])
						{
							alreadyShown = true;
							break;
						}
					}
					
					for(int o = 0; o < shownCards.length; o++)
					{
						if(shownCards[o] == -1 && !alreadyShown)
						{
							shownCards[o] = cardList[selCardIndex];
							break;
						}
						else if(shownCards[o] == cardList[selCardIndex] && alreadyShown)
						{
							shownCards[o] = -1;
							break;
						}
					}
					clearKeys();
				}
				else if(isKeyPressed(KEYS.KEY_LSK))
				{
					if(shownCards[0] != -1 && tegCountries[shownCards[0]].owner == cPlayer.turn && shownCards[1] == -1 && shownCards[2] == -1 && !tegCountries[shownCards[0]].usedCard)
					{
						showCard = false;
						tegCountries[shownCards[0]].armies += 2;
						tegCountries[shownCards[0]].usedCard = true;
						clearKeys();
					}
					else if(shownCards[0] != -1 && shownCards[1] != -1 && shownCards[2] != -1)
					{
						if(((tegCountries[shownCards[0]].cardImage == tegCountries[shownCards[1]].cardImage) && (tegCountries[shownCards[0]].cardImage == tegCountries[shownCards[2]].cardImage)) || ((tegCountries[shownCards[0]].cardImage != tegCountries[shownCards[1]].cardImage) && (tegCountries[shownCards[0]].cardImage != tegCountries[shownCards[2]].cardImage) && (tegCountries[shownCards[1]].cardImage != tegCountries[shownCards[2]].cardImage)))
						{
							for(int s = 0; s < shownCards.length; s++)
							{
								tegCountries[shownCards[s]].cardOwner = -1;
								tegCountries[shownCards[s]].usedCard = false;
								shownCards[s] = -1;
							}
							
							tegPlayers[cPlayer.turn].changeNumber++;
							
							switch(cPlayer.roundType)
							{
								case INGAME.ROUND_TYPE_PUT_ARMIES:
									if(tegPlayers[cPlayer.turn].changeNumber < 3)
										tegPlayers[cPlayer.turn].armies += rules[RULES.FIRST_CHANGE + tegPlayers[cPlayer.turn].changeNumber];
									else
										tegPlayers[cPlayer.turn].armies += rules[RULES.FIRST_CHANGE + 2] + rules[RULES.CHANGE_INCREMENT] * tegPlayers[cPlayer.turn].changeNumber - 2;
								break;
								case INGAME.ROUND_TYPE_ATTACK:
									if(tegPlayers[cPlayer.turn].changeNumber < 3)
										tegCountries[tegPlayers[cPlayer.turn].lastConqueredCountry].armies += rules[RULES.FIRST_CHANGE + tegPlayers[cPlayer.turn].changeNumber];
									else
										tegCountries[tegPlayers[cPlayer.turn].lastConqueredCountry].armies += rules[RULES.FIRST_CHANGE + 2] + rules[RULES.CHANGE_INCREMENT] * tegPlayers[cPlayer.turn].changeNumber - 2;
										
									hasPickedCard = true;
								break;
							}
						}
					}
				}
				else if(isKeyPressed(KEYS.KEY_RSK))
				{
					toolsState = TOOLS_STATE_MAIN;
					for(int q = 0; q < shownCards.length; q++)
					{
						shownCards[q] = -1;
					}
					clearKeys();
				}
				
				cGame_g.setFont(DGraph.FONT_BIG);
				
			break;
			
			case TOOLS_STATE_OBJECTIVE:
			
				cGame_g.setFontColor(SOFTKEYS.COLOR);
				drawSoftKeys(SOFTKEYS.STR_NONE, SOFTKEYS.STR_BACK);
				drawObjective(tegPlayers[cPlayer.turn].objectiveId);
		
				if(isKeyPressed(KEYS.KEY_RSK))
				{
					toolsState = TOOLS_STATE_MAIN;
					clearKeys();
				}
				
			break;
		}
	}
	
	void drawObjective(int objId)
	{
		cGame_g.setColor(CARDS.CARD_COLOR);
		cGame_g.fillRect(INGAME.OBJECTIVE_X, INGAME.OBJECTIVE_Y, INGAME.OBJECTIVE_W, INGAME.OBJECTIVE_H);
		cGame_g.setFont(DGraph.FONT_SMALL);
		cGame_g.setFontColor(CARDS.CARD_TEXT_COLOR);
		cGame_g.drawString(TEXT.OBJECTIVES[objId], SCREEN_WIDTH / 2, INGAME.OBJECTIVE_Y + cGame_g.getFontHeight(), INGAME.OBJECTIVE_W - cGame_g.getFontWidth() * 3, DSmallFont.HCENTER | DSmallFont.TOP);
		#ifndef REMOVE_IMAGES
		cGame_g.drawRegion(cardsImg, SPRITES.CARD_MODULE_X[SPRITES.CARD_THING], SPRITES.CARD_MODULE_Y[SPRITES.CARD_THING], SPRITES.CARD_MODULE_W[SPRITES.CARD_THING], SPRITES.CARD_MODULE_H[SPRITES.CARD_THING], 0, INGAME.OBJECTIVE_X + INGAME.OBJECTIVE_W - SPRITES.CARD_MODULE_W[SPRITES.CARD_THING] - SPRITES.CARD_MODULE_W[SPRITES.CARD_THING] / 3, INGAME.OBJECTIVE_Y + INGAME.OBJECTIVE_H - SPRITES.CARD_MODULE_H[SPRITES.CARD_THING] - SPRITES.CARD_MODULE_H[SPRITES.CARD_THING] / 3, 0);
		#endif
		cGame_g.setFont(DGraph.FONT_BIG);
	}